var express = require('express');
var router = express.Router();
var {login }= require("../controller/user")
const { SuccessModel ,EeeorModel} = require("../model/resModel")

/* GET users listing. */
router.post('/login', function(req, res, next) {

const { username , password} = req.body

const result = login(username,password)

result.then(data =>{
    if(data.username){
        req.session.username =   data.username
        req.session.realname = data.realname

        res.json(
            new SuccessModel("登陆成功")
        )
        return
    }
    res.json(
        new EeeorModel("登陆失败")
    )
})



  
});

/* router.get("/session-test",(req,res,next) =>{
   const session = req.session
   if(session.viewNum == null){
       session.viewNum = 0
   }
   session.viewNum++

   res.json({
       viewNum: session.viewNum
   })
}) */

module.exports = router;
